package com.guiwu.gteway.industryapp.Device.module;

import android.os.Parcel;
import android.os.Parcelable;

import com.google.gson.annotations.SerializedName;

/**
 * Created by qiaoguan on 2018/3/26. 网关地址
 */

public class GateWayLocation implements Parcelable{

    @SerializedName("lon")
    private String longitude;
    @SerializedName("lat")
    private String latitude;
    private String ele;


    protected GateWayLocation(Parcel in) {
        longitude = in.readString();
        latitude = in.readString();
        ele = in.readString();
    }

    public double getLongitude() {
        return turnDouble(longitude);
    }

    public double getLatitude() {
        return turnDouble(latitude);
    }

    public double getEle() {
        return turnDouble(ele);
    }

    private double turnDouble(String doubleString){
        double returnDouble;
        try {
            returnDouble = Double.parseDouble(doubleString);
        }catch (NumberFormatException e) {
            returnDouble = 0;
            e.printStackTrace();
        }
        return returnDouble;
    }

    public static final Creator<GateWayLocation> CREATOR = new Creator<GateWayLocation>() {
        @Override
        public GateWayLocation createFromParcel(Parcel in) {
            return new GateWayLocation(in);
        }

        @Override
        public GateWayLocation[] newArray(int size) {
            return new GateWayLocation[size];
        }
    };

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(longitude);
        dest.writeString(latitude);
        dest.writeString(ele);
    }

    @Override
    public String toString() {
        return "  lon:"+ longitude + "  lat" + latitude + "  ele" + ele;
    }
}
